package com.mchsdk.paysdk.bean;

import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

import com.mchsdk.open.UploadRoleCallBack;
import com.mchsdk.paysdk.common.Constant;
import com.mchsdk.paysdk.http.process.UploadRoleProcess;
import com.mchsdk.paysdk.utils.MCLog;

/**
 * Created by smile on 2017/8/18.
 * 上传角色
 */

public class UploadRole {

    public static final String TAG = "UploadRole";
    String gameId;
    String serverId;
    String serverName;
    String roleName;
    String roleLevel;
    UploadRoleCallBack roleCallBack;


    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case Constant.UPLOAD_ROLE_SUCCESS:// 修改成功
                    if (null != getRoleCallBack()) {
                        getRoleCallBack().onUploadComplete("1");
                    }
                    break;
                case Constant.UPLOAD_ROLE_FAIL:// 修改失败
                    if (null != getRoleCallBack()) {
                        getRoleCallBack().onUploadComplete("0");
                    }
                    break;
            }
        }
    };

    public UploadRole(String gameId, String serverId, String serverName,
                      String roleName, String roleLevel, UploadRoleCallBack roleCallBack) {
        if (null==serverName||null==roleLevel){
            MCLog.e(TAG, "fun#uploadRole userId、roleLevel、serverName must be not null\n"
                    + "serverName\t" + serverName + "\n"
                    + "roleName\t" + roleName + "\n"
                    + "roleLevel\t" + roleLevel);
        }
        this.gameId=gameId;
        this.serverId=serverId;
        this.serverName=serverName;
        this.roleName=roleName;
        this.roleLevel=roleLevel;
        this.roleCallBack=roleCallBack;
    }


    public void upload(){
        if (null == PersonalCenterModel.getInstance().channelAndGame
                || TextUtils
                .isEmpty(PersonalCenterModel.getInstance().channelAndGame
                        .getAccount())) {
            MCLog.w(TAG,"请登录");
            return;
        }
        UploadRoleProcess roleProcess=new UploadRoleProcess();
        roleProcess.setServerName(this.serverName);
        roleProcess.setRoleName(this.roleName);
        roleProcess.setRoleLevel(this.roleLevel);
        roleProcess.setServerId(this.serverId);
        roleProcess.post(mHandler);
    }

    public UploadRoleCallBack getRoleCallBack() {
        if (roleCallBack != null) {
            return roleCallBack;
        }
        return null;
    }
}
